package com.net.xpay.admin.controller.admin;
import com.net.common.model.ResultData;
import com.net.xpay.admin.po.TransStatPo;
import com.net.xpay.admin.vo.TransStatVo;
import com.net.xpay.common.domain.stat.TransStat;
import com.net.xpay.common.model.TransStatSumDataModel;
import com.net.xpay.common.service.TransStatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/trans-stat")
@Api(tags = "运营/转账统计",description = "转账统计")
public class AdminTransStatController {
    @Autowired
    private TransStatService transStatService;



    @ApiOperation("按日期统计")
    @PostMapping("/sum")
    @ResponseBody
    @PreAuthorize("hasAnyRole('ADMIN', 'trans-stat::sum')")
    public ResultData<TransStatVo> sumTransStat(@RequestBody TransStatPo transStatPo) {
        TransStatVo vo = new TransStatVo();
        TransStat todayStat = transStatService.sumTransStat(transStatPo.getDay());
        vo.setTodayStat(todayStat);

        TransStat yesterdayStat = transStatService.sumTransStat(transStatPo.getDay().minusDays(1L));
        vo.setYesterdayStat(yesterdayStat);

        TransStatSumDataModel sumData = transStatService.getSumData();
        vo.setSumData(sumData);

        return new ResultData<>(vo);
    }
}
